package com.zhdl.modules.demo.dglProcess.camera;

import com.project.common.util.DelayUtil;
import com.zhdl.common.ytools.callback.CommonCallback;
import com.zhdl.hardware_contact.hardware_config.entity.ProjectConfiguration;
import com.zhdl.modules.process.service.BaseConfigValueProvider;
import org.springframework.stereotype.Service;

import java.util.Random;
@Service
public class DGLCameraService extends BaseConfigValueProvider implements CameraTakePhotoService {
    public static final String RESULT_OK = "result_ok";
    public static final String TAKE_PHOTO_DONE = "take_photo_done";
    public   float[] REGIONLOCATION = new float[6];
    @Override
    public void takePhoto(int cameraNo, int location, CommonCallback<CameraResult> cameraResultCommonCallback) {
        float[] locationResult = new float[6];
        DelayUtil.delayedExecution(6000, () -> {
            CameraResult cameraResult = new CameraResult();
            cameraResult.setResultOK(true);
            locationResult[0] = new Random().nextFloat()*100.0f;
            locationResult[1] = new Random().nextFloat()*100.0f;
            locationResult[2] = new Random().nextFloat()*100.0f;
            cameraResult.setLocation(locationResult);
            cameraResultCommonCallback.statusCallback(cameraResult);
        });
    }

    @Override
    public void initData() {
        configurationPLcList.add(new ProjectConfiguration(RESULT_OK,"0",1));
        configurationPLcList.add(new ProjectConfiguration(TAKE_PHOTO_DONE,"0",1));
    }
}
